package com.certificationManager.client.presenter;

import com.certificationManager.client.CMEventBus;
import com.certificationManager.client.presenter.view_interface.IMainStructureView;
import com.certificationManager.client.util.UserUtils;
import com.certificationManager.client.view.MainStructureView;
import com.extjs.gxt.ui.client.event.Listener;
import com.extjs.gxt.ui.client.event.MessageBoxEvent;
import com.extjs.gxt.ui.client.widget.Dialog;
import com.extjs.gxt.ui.client.widget.MessageBox;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.mvp4g.client.annotation.Presenter;
import com.mvp4g.client.presenter.BasePresenter;

/**
 * @author Benjamin Barbier
 *
 */
@Presenter( view = MainStructureView.class )
public class MainStructurePresenter extends BasePresenter<IMainStructureView, CMEventBus> {

	public void onGoToMainStructure() {
		eventBus.changeBody(view.getViewWidget());
	}
	
	@Override
	public void bind(){
		
		view.getTopView().getDisconnectLink().addClickHandler(new ClickHandler() {
			@Override
			public void onClick(ClickEvent event) {
				MessageBox.confirm("Disconnect", "Etes-vous sûr de vouloir quiter 'Certification-Manager' ?",
					new Listener<MessageBoxEvent>() {
						@Override
						public void handleEvent(MessageBoxEvent be) {
							if (Dialog.YES.equals(be.getButtonClicked().getText())) {
								UserUtils.getInstance().disconnect();
								//TODO: Afficher la page de départ...
								eventBus.goToLogin();
							}
						}
				});
			}
		});
		
		view.getTopView().getHelpLink().addClickHandler(new ClickHandler() {
			@Override
			public void onClick(ClickEvent event) {
				MessageBox.alert("Aide","Aide !", null);
			}
		});
		
		view.getTopView().getAboutLink().addClickHandler(new ClickHandler() {
			@Override
			public void onClick(ClickEvent event) {
				MessageBox.info("Info", "A propos !", null);
			}
		});
		
		
	}
	
}
